package utils
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	public class GetMapArray extends Sprite{
		private var isDown:Boolean;
		private var isClick:Boolean;
		private var ball:Sprite;
		private var mapArr:Array=[];
		
		public function getPoint():void{
			addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandle);
			addEventListener(MouseEvent.MOUSE_UP,mouseUpHandle);
			addEventListener(MouseEvent.CLICK,mouseClickHandle);
			
			addEventListener(Event.ENTER_FRAME,enterFrameHandle);
			ball = new Sprite();
			addChild(ball);
			ball.graphics.beginFill(0xff6699);
			ball.graphics.drawCircle(0,0,3);
			ball.graphics.endFill();
			
		}
		
		protected function mouseClickHandle(event:MouseEvent):void
		{
			isClick = true;
		}
		
		private function mouseDownHandle(e:MouseEvent):void{
			isDown = true;
			mapArr.push(new Point(mouseX,mouseY))
		}
		private function mouseUpHandle(e:MouseEvent):void{
			isDown = false;
		}
		
		private function enterFrameHandle(e:Event):void{
			if(!isDown) return;
			var p:Point = new Point(mouseX,mouseY);
			var p2:Point = mapArr[mapArr.length-1];
			var dis:Number = Point.distance(p,p2);
			if(dis>=4){
				mapArr.push(p);
				ball.x = p.x;
				ball.y = p.y;
			}
			
			if(isClick){
				removeEventListener(Event.ENTER_FRAME,enterFrameHandle);
				trace(mapArr.length);
				trace(mapArr);
			}
		}
		
	}
}